﻿#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<list>
#include<map>
#include<vector>
#include"mymap.h"
#include"myset.h"
using namespace std;

void TestTree2()
{
	const int N = 1000;
	vector<int> v;
	v.reserve(N);
	srand(time(0));
	for (size_t i = 0; i < N; i++)
	{
		v.push_back(rand() + i);
	}

	size_t begin2 = clock();
	mymap<int, int> t;
	for (auto e : v)
	{
		t.Insert(make_pair(e, e));
	}
	size_t end2 = clock();

	size_t begin22 = clock();
	mymap<int, int> rbt;
	for (auto e : v)
	{
		rbt.Insert(make_pair(e, e));
	}
	size_t end22 = clock();

	cout << "AVL Insert:" << end2 - begin2 << endl;
	//cout << "RB Insert:" << end22 - begin22 << endl;

	/*cout <<"AVL IsBalance:"<< t.IsBalanceTree() << endl;
	cout << "RB IsBalance:" << rbt.IsBalance() << endl;*//*


	cout << "AVL Height:" << t.Height() << endl;
	cout << "AVL Size:" << t.Size() << endl;

	cout << "RB Height:" << rbt.Height() << endl;
	cout << "RB Size:" << rbt.Size() << endl;*/

	size_t begin1 = clock();
	// 确定在的值
	/*for (auto e : v)
	{
		t.Find(e);
	}*/
	// 随机值
	/*for (size_t i = 0; i < N; i++)
	{
		t.Find((rand() + i));
	}*/
	size_t end1 = clock();
	cout << "AVL Find:" << end1 - begin1 << endl;
	/*for (auto e : t) {
		cout << e.first << endl;
	}*/

	size_t begin11 = clock();
	// 确定在的值
	/*for (auto e : v)
	{
		rbt.Find(e);
	}*/
	// 随机值
	/*for (size_t i = 0; i < N; i++)
	{
		t.Find((rand() + i));
	}*/
	size_t end11 = clock(); 
	cout << "RB Find:" << end11 - begin11 << endl;
}


void test_map()
{

	mymap<string, string> dict;
	dict.Insert({ "sort", "排序" });
	dict.Insert({ "left", "左边" });
	dict.Insert({ "right", "右边" });
	dict["left"] = "左边，剩余";
	dict["insert"] = "插入";
	dict["string"];
	mymap<string, string>::iterator it = dict.begin();
	//while (it != dict.end())
	//{
	//	// 不能修改first，可以修改second
	//	//it->first += 'x';
	//	it->second += 'x';
	//	cout << it->first << ":" << it->second << endl;
	//	++it;
	//}
	cout << endl;
}
void test_set()
{
	myset<int> s;
	int a[] = { 4, 2, 6, 1, 3, 5, 15, 7, 16, 14 };
	for (auto e : a)
	{
		s.Insert(e);
	}
	for (auto e : s)
	{
		cout << e << " ";
	}
	cout << endl;
	s.print();
}


int main() {
	
	
	//TestTree2();
	//test_set(); 
	test_map();
	//vector<int>arrr(arr,arr3);
	mymap<int, int> c;
	c.Insert(make_pair(18, 0));
	c.Insert(make_pair(10, 0));
	c.Insert(make_pair(15, 0));
	c.Insert(make_pair(30, 0));
	c.Insert(make_pair(25, 0));
	c.Insert(make_pair(40, 0));
	c.Insert(make_pair(35, 0));
	c.Insert(make_pair(50, 0));
	mymap<int, int>::iterator st = c.begin();
	mymap<int, int>::constiterator stt = st;
	cout << stt->first << " ";
	++stt;
	mymap<int, int> CC = c;
	const map<int, int> y(c.begin(), c.end());
	//y[18];
	for (auto e : y) {
		cout << e.first << endl;
	}
	//mymap<int, int> j = c;
	c[18]++;
	auto kk = c.begin();
	auto cc = c.begin();
	
	c.print();
	myset<int> a;
	a.Insert(2);
	a.Insert(4);
	a.Insert(5);
	a.Insert(3);
	cout << endl;
	++c[18];
	cout << c[18] << endl;
	auto aaa = c.end();
	--aaa; cout << aaa->first << endl;
	for (; aaa != c.end(); --aaa) {
		cout << aaa->first << endl;
	}
	//--aaa; cout << aaa->first << endl;
	//a.print();
	//int arr[] = { 1,2,3,4,5,6 };
	

	return 0;
}